Check Leap Year

Theory:

A leap year is a year that is evenly divisible by 4, except for years that are evenly divisible by 100. However, years that are evenly divisible by 400 are also leap years.

Python Code:

def is_leap_year(year):
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return True
            else:
                return False
        else:
            return True
    else:
        return False

# Taking input for year and checking if it's a leap year
def check_leap_year():
    year = int(input("Enter a year to check if it's a leap year: "))
    if is_leap_year(year):
        print(year, "is a leap year.")
    else:
        print(year, "is not a leap year.")

check_leap_year()

Example Output 1:

Enter a year to check if it's a leap year: 2000

2000 is a leap year.

Example Output 2:

Enter a year to check if it's a leap year: 1900

1900 is not a leap year.

Code Explanation:

The function is_leap_year(year) checks whether a given year is a leap year or not based on the leap year rules.

The function check_leap_year() takes input for the year, checks if it's a leap year using the aforementioned function, and prints the result.